package com.bsj.sipgateway.sip.bean;

import com.bsj.sipgateway.common.def.DvehicleInfo;
import com.bsj.sipgateway.mysql.bsj.vehicle.entity.Vehicle;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.*;

/**
 * @Author WPH
 * @Description
 * @Date 2022/8/15 19:07
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class VehicleInfo {
    private Long vehicleId;

    private Integer groupId;

    private String terminalNo;

    private String plate;

    private Map<String,String> channelMap;

    private String terminalType;

    public VehicleInfo(DvehicleInfo info) {
        this.vehicleId = info.getVehicleId();
        this.groupId = info.getGroupId();
        this.terminalNo = info.getTerminalNo();
        this.plate = info.getPlate();
        this.channelMap = new HashMap<>();
        this.terminalType = info.getTerminalType();

        String[] cameraLineS = null;
        List<String> cameraLineMap = new ArrayList<>();
        if (info.getCameraLine()!=null) {
            cameraLineS = info.getCameraLine().replace("[", "").replace("]", "").split(",");
            cameraLineMap.addAll(Arrays.asList(cameraLineS));
        }

        String[] channelIds = null;
        List<String> channelIdList = new ArrayList<>();
        if (info.getCameraChannelId() != null) {
            channelIds = info.getCameraChannelId().replace("[", "").replace("]", "").split(",");
            channelIdList.addAll(Arrays.asList(channelIds));
        }

        if (cameraLineMap.size()==channelIdList.size()){
            for (int i = 0; i < cameraLineMap.size(); i++) {
                channelMap.put(cameraLineMap.get(i),channelIdList.get(i));
            }
        }
    }

    public VehicleInfo(Vehicle info) {
        this.vehicleId = info.getVehicleId();
        this.groupId = info.getGroupId();
        this.terminalNo = info.getTerminalNo();
        this.plate = info.getPlate();
        this.channelMap = new HashMap<>();
        this.terminalType = info.getTerminalType();
        String[] cameraLineS = null;
        List<String> cameraLineMap = new ArrayList<>();
        if (info.getCameraLine()!=null) {
            cameraLineS = info.getCameraLine().replace("[", "").replace("]", "").split(",");
            cameraLineMap.addAll(Arrays.asList(cameraLineS));
        }

        String[] channelIds = null;
        List<String> channelIdList = new ArrayList<>();
        if (info.getCameraChannelId() != null) {
            channelIds = info.getCameraChannelId().replace("[", "").replace("]", "").split(",");
            channelIdList.addAll(Arrays.asList(channelIds));
        }

        if (cameraLineMap.size()==channelIdList.size()){
            for (int i = 0; i < cameraLineMap.size(); i++) {
                channelMap.put(cameraLineMap.get(i),channelIdList.get(i));
            }
        }
    }
    public String getChannelId(String cameraLine){
        return channelMap.get(cameraLine);
    }
}
